package com.itheima.homework.homework4;

public class Worker {
    private  String name;
    private int age;

    public Worker() {
    }

    public Worker(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        /*
                work1 == this
                work2 ==  o
         */
        //判断地址是否相同
        if (this == o) return true;

        //如果work2为空,或者work1和work2的类型不同,直接返回false
        if (o == null || this.getClass() != o.getClass()) return false;

        Worker worker = (Worker) o; //worker == work2

        if (this.age != worker.age) return false;
        return name != null ? name.equals(worker.name) : worker.name == null;
    }


}
